<?php
namespace PsiFramework\Classes\Util\Log;

import("Classes.Util.Object.Date");

use \PsiFramework\Classes\Util\Object\Date;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The LoggerManager class is used to manage logs
 *
 * @package Util.Log
 */
class LoggerManager
{

    protected static /*LoggerManager*/ $_singleton ;

    protected /*string[]*/ $_logs ;

    /**
     * Constructor
     */
    protected function __construct()
    {
        $this->_logs = array();
    }

    /**
     * Adds a log entry
     *
     * @param string $className
     * @param string $level
     * @param string $message
     */
    public function addLog(
        /*string*/ $className,
        /*string*/ $level,
        /*string*/ $message
    )
    {
        $date = Date::now();
        $log = $date->getDateTime() . 
               " [" . $level .  "] " .
               $className . " - " . $message ;
        $this->_logs[] = $log ;
    }

    /**
     * Returns the logs as a text block
     *
     * @return    string    the logs
     */
    public function getLogs()
    {
        $text = "" ;
        foreach ($this->_logs as $log) {
            $text .= $log . "\n" ;
        }
        return $text ;
    }

    /**
     * This function must be called instead of the construtor
     *
     * @return LoggerManager instance
     */
    public static function getInstance()
    {

        if (self::$_singleton == null) {
            self::$_singleton = new LoggerManager();
        }

        return self::$_singleton;
    }

}
